home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’89 / SpiNit / SpiNit.p < prev    next >
Encoding:
Text File  |  1989-06-16  |  3.3 KB  |  117 lines  |  [TEXT/MPS ]

  1. {  File:    SpiNit.p
  2.    By:      Jonathan Gary & Bill Johnson
  3.    Date:    6/15/89
  4.    Purpose: To annoy the user to the max.
  5.    This routine is called by a patch to show window.
  6.    Then we criminally draw a spinning rect into the WMgrPort.
  7.    Inspired by the old time movies and Pythagoreas [sp].
  8. }
  9.  
  10.  
  11. UNIT SpuNit;
  12.  
  13. INTERFACE
  14.  
  15. USES
  16.     MemTYPEs, QuickDraw, OSIntf, PasLibIntf, ToolIntf, SANE, PackIntf;
  17.  
  18. PROCEDURE SpinFrame (wPtr: WindowPtr);
  19.                      
  20. IMPLEMENTATION
  21.  
  22. PROCEDURE SpinFrame (wPtr: WindowPtr);
  23.     CONST
  24.         kAngleStep = 60;
  25.         kAngleOffset = 10;
  26.         kZoomSteps = 4;
  27.         kClipSize = 32000;
  28.  
  29. { this is wrong, but so what!}
  30.  
  31.     FUNCTION CenterOfRect (theRect: Rect): Point;
  32.  
  33.     BEGIN
  34.         CenterOfRect.h := (theRect.left + (theRect.right - theRect.left) DIV 2);
  35.         CenterOfRect.v := (theRect.top + (theRect.bottom - theRect.top) DIV 2);
  36.     END;
  37.  
  38.     VAR
  39.         oldTop, oldBot, oldLeft, oldRight: integer;
  40.         center: Point;
  41.         wMgrPort, savePort: GrafPtr;
  42.         hSize, vSize, stepVSize, stepHSize, height, width, offset1, offset2, onOff, hh, vv: integer;
  43.         zoomStep, step, loopLimit: integer;
  44.         theta: Real;
  45.         anotherRect, spinRect: Rect;
  46.         saveClip: RgnHandle;
  47.         savePen: PenState;
  48.         finalTick: longint;
  49.         sinArr1, sinArr2, cosArr1, cosArr2: ARRAY[0..12] OF real;
  50.  
  51. BEGIN
  52.     GetPort(savePort);
  53.     SetPort(wPtr);
  54.     spinRect := wPtr^.portRect;
  55.     LocalToGlobal(spinRect.topLeft);
  56.     LocalToGlobal(spinRect.botRight);
  57.     center := CenterOfRect(spinRect);
  58.     oldTop := spinRect.top;
  59.     oldBot := spinRect.bottom;
  60.     oldLeft := spinRect.left;
  61.     oldRight := spinRect.right;
  62.     hSize := oldRight - oldLeft;
  63.     vSize := oldbot - oldtop;
  64.     loopLimit := 360 DIV kAngleStep;
  65.     GetWMgrPort(wMgrPort);
  66.     SetPort(wMgrPort);
  67.     GetPenState(savePen);
  68.     PenMode(patXor);
  69.     PenSize(2, 2);
  70.     saveClip := NewRgn;
  71.     GetClip(saveClip);
  72.     SetRect(anotherRect, -32000, -32000, 32000, 32000);
  73.     ClipRect(anotherRect);
  74. { init trig tables -- I know, it's semi -  redundant  }
  75.     sinArr1[0]:= 0.173648;cosArr1[0]:= 0.984808;sinArr2[0]:= 0.984808;cosArr2[0]:= -0.173648;
  76.     sinArr1[1]:= 0.939692;cosArr1[1]:= 0.342021;sinArr2[1]:= 0.34202;cosArr2[1]:= -0.939693;
  77.     sinArr1[2]:= 0.766044;cosArr1[2]:= -0.642788;sinArr2[2]:= -0.642787;cosArr2[2]:= -0.766045;
  78.     sinArr1[3]:= -0.173649;cosArr1[3]:= -0.984808;sinArr2[3]:= -0.984808;cosArr2[3]:= 0.173648;
  79.     sinArr1[4]:= -0.939693;cosArr1[4]:= -0.34202;sinArr2[4]:= -0.342021;cosArr2[4]:= 0.939692;
  80.     sinArr1[5]:= -0.766044;cosArr1[5]:= 0.642788;sinArr2[5]:= 0.642788;cosArr2[5]:= 0.766044;
  81.     sinArr1[6]:= 0.173648;cosArr1[6]:= 0.984808;sinArr2[6]:= 0.984808;cosArr2[6]:= -0.173649;
  82.     
  83.  
  84.     FOR zoomStep := kZoomSteps DOWNTO 2 DO
  85.         BEGIN
  86.  
  87.  
  88.             FOR step := 0 TO loopLimit - 1 DO
  89.                 BEGIN
  90.                     width := trunc(sinArr1[step] * (hSize)) div zoomStep;
  91.                     height := trunc(cosArr1[step] * (hSize)) div zoomStep;
  92.                     hh := trunc(sinArr2[step] * (vSize)) div zoomStep;
  93.                     vv := trunc(cosArr2[step] * (vSize)) div zoomStep;
  94.                     stepVSize := (-height DIV 2);
  95.                     stepHSize := (-width DIV 2);
  96.                     FOR onOff := 1 TO 2 DO
  97.                         BEGIN
  98.                             MoveTo(center.h, center.v);
  99.                             Move(stepHSize, stepVSize);
  100.                             Line(width, height);
  101.                             Line(hh, vv);
  102.                             MoveTo(center.h, center.v);
  103.                             Move(stepHSize, stepVSize);
  104.                             Line(hh, vv);
  105.                             Line(width, height);
  106.                             Delay(1, finalTick);  { cheesey - wait for retrace }
  107.                         END;
  108.                 END;
  109.         END;
  110.     SetClip(saveClip);
  111.     DisposeRgn(saveClip);
  112.     SetPenState(savePen);
  113.     SetPort(savePort);
  114. END;
  115.  
  116.  
  117. END.    { of unit }